package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId) {
        UserInfoVo vo = messagesService.findUserInfoByHuanxin(huanxinId);
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map<String,Long> map) {
        Long userId = map.get("userId");
        messagesService.contacts(userId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/contacts")
    public ResponseEntity contactList(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,String keyword) {
        PageResult pageResult = messagesService.contactList(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }

}
